from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class UserProfileInfo(models.Model):
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    portfolio_site = models.URLField(blank=True)
    profile_pic = models.ImageField(upload_to='profile_pics',blank=True)
    def __str__(self):
      return self.user.username

class LogFile(models.Model):
    # id = models.AutoField(primary_key=True)
    techsuppid = models.IntegerField(default=0)
    techsupptype = models.CharField(max_length=512, default='nGeniusONE')
    filename = models.CharField(max_length=512)
    fullfilename = models.CharField(max_length=512)
    postime = models.DateTimeField(auto_now_add=True)
    serialnumber = models.CharField(max_length=512, default='-')
    version = models.CharField(max_length=512, default='-')
    build = models.CharField(max_length=512, default='-')
    customername = models.CharField(max_length=512, default='-')
    status = models.CharField(max_length=128, default='pending')
    comments = models.CharField(max_length=1024, null=True)
    postedby = models.ForeignKey(User, on_delete=models.CASCADE)
    # permission = models.IntegerField(default=0)
    shared = models.BooleanField(default=False)

    def postTimeDisplay(self):
        return self.postime.strftime('%d-%m-%Y %H:%M:%S')

class summary(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE)
    summary = models.TextField(default='This should be a summary for the log file.')

class sharetable(models.Model):
    shareid = models.ForeignKey(LogFile, on_delete=models.CASCADE)
    # sharedto = models.CharField(max_length=50, default="Anonymous")
    sharedto = models.ForeignKey(User, on_delete=models.CASCADE)
    accesstime = models.DateTimeField(auto_now=True)
    accesstimes = models.IntegerField(default=0)
    openby = models.CharField(max_length=50, default="Anonymous")
    logname = models.CharField(max_length=512, default="")


class highmemdetec(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE)
    processname = models.CharField(max_length=512)
    memoryfile = models.CharField(max_length=512, null=True)
    heapsize = models.CharField(max_length=512, null=True)
    maximumutil =  models.IntegerField(default=0)
    restartcounter =  models.IntegerField(default=0)
    maximumdetail = models.TextField(null=True)
    restartdetail = models.TextField(null=True)
    summarylog = models.CharField(max_length=512, null=True)

class propcompare(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE)
    propname = models.CharField(max_length=512)
    propfullname = models.TextField(null=True)
    diff = models.IntegerField(default=0)
    mismatched = models.TextField(null=True)
    extra = models.TextField(null=True)
    missing = models.TextField(null=True)
    difffilename = models.CharField(max_length=512, null=True)

class knownissue(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE)
    scantype = models.IntegerField(default=-1)
    healthy_level = models.IntegerField(default=0)
    short_description = models.TextField(null=True)
    detail_info = models.TextField(null=True)
    logfilefullname = models.TextField(null=True)
    name = models.CharField(max_length=512, null=True)

class hierachy(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE)
    weekday = models.CharField(max_length=200, null=True)
    mename = models.CharField(max_length=200, null=True)
    level = models.CharField(max_length=200, null=True)
    meversion = models.CharField(max_length=200, null=True)
    metype = models.CharField(max_length=200, null=True)
    parentname = models.CharField(max_length=200, null=True)
    dataloaded = models.BooleanField(default=False)
    colsname = models.CharField(max_length=512, null=True)
    logfilename = models.CharField(max_length=1024, null=True)
    status = models.CharField(max_length=50, null=True)


class pollingdata(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE)
    hierachynodeid = models.ForeignKey(hierachy, on_delete=models.CASCADE)
    time = models.CharField(max_length=256, null=True)
    c1 = models.CharField(max_length=256, null=True)
    c2 = models.CharField(max_length=256, null=True)
    c3 = models.CharField(max_length=256, null=True)
    c4 = models.CharField(max_length=256, null=True)
    c5 = models.CharField(max_length=256, null=True)
    c6 = models.CharField(max_length=256, null=True)
    c7 = models.CharField(max_length=256, null=True)
    c8 = models.CharField(max_length=256, null=True)
    c9 = models.CharField(max_length=256, null=True)
    c10 = models.CharField(max_length=256, null=True)
    c11 = models.CharField(max_length=256, null=True)
    c12 = models.CharField(max_length=256, null=True)
    c13 = models.CharField(max_length=256, null=True)
    c14 = models.CharField(max_length=256, null=True)
    c15 = models.CharField(max_length=256, null=True)
    c16 = models.CharField(max_length=256, null=True)
    c17 = models.CharField(max_length=256, null=True)
    c18 = models.CharField(max_length=256, null=True)
    c19 = models.CharField(max_length=256, null=True)
    c20 = models.CharField(max_length=256, null=True)
    c21 = models.CharField(max_length=256, null=True)
    c22 = models.CharField(max_length=256, null=True)
    c23 = models.CharField(max_length=256, null=True)
    c24 = models.CharField(max_length=256, null=True)
    c25 = models.CharField(max_length=256, null=True)

class logscanjob(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE) 
    scanscope = models.CharField(max_length=256, null=True)
    scanned = models.BooleanField(default=False)
    scanstatus = models.CharField(max_length=100, null=True)
    path = models.CharField(max_length=256, null=True)
    typepath = models.CharField(max_length=256, null=True)

class logscanitems(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE) 
    itemname = models.CharField(max_length=256, null=True) 
    jobid_id = models.IntegerField(default=0)
    healthy = models.IntegerField(default=0)

class logscanoutput(models.Model):
    techsuppid = models.ForeignKey(LogFile, on_delete=models.CASCADE) 
    itemid = models.ForeignKey(logscanitems, on_delete=models.CASCADE) 
    errormsg = models.CharField(max_length=512, null=True)
    occurrence = models.IntegerField(default=0)
    proposedaction = models.CharField(max_length=512, null=True)
    detaillog = models.TextField()


